package com.cn.wanxi.dao.impl;

import com.cn.wanxi.dao.BaseDao;
import com.cn.wanxi.util.JDBC;

import java.util.List;
import java.util.Map;


public class ProductImpl implements BaseDao {
    @Override
    public List<Map> getList(Object object) {
        return JDBC.excuteQuery("SELECT a.id,a.name,a.mainmaterial,a.content,a.price,a.marketPrice,a.imgUrl,a.cookStyleId,b.name as cookStyleName FROM product a inner join cookstyle b on a.cookStyleId=b.id " + object, null);
    }

    @Override
    public Object getModel(Object object) {
        return JDBC.excuteQuery("select * from product where id=" + object, null);
    }

    @Override
    public int add(Object object) {
        return JDBC.executeUpdate("insert into product(name,mainmaterial, content, price, marketPrice, imgUrl, cookstyleid) values(?,?,?,?,?,?,?)", object);
    }

    @Override
    public int update(Object object) {
        return JDBC.executeUpdate("update product set name = ?,mainmaterial = ?, content = ?, price = ?, marketPrice = ?, imgUrl = ?, cookstyleid = ? where id = ?", object);
    }

    @Override
    public int delete(Object object) {
        return JDBC.executeUpdate("delete from product where id=?", object);
    }

    @Override
    public List<Map> getDataNum(Object object) {
        return JDBC.excuteQuery("select count(id) as num from product", object);
    }
}
